package com.tanhua.server.controller;

import com.tanhua.domain.vo.CommentVo;
import com.tanhua.domain.vo.NearUserVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 搜附近控制层
 */
@RestController
public class LocationController {

    @Autowired
    private LocationService locationService;

    /**
     * 上报地理位置
     */
    @RequestMapping(value = "/baidu/location",method = RequestMethod.POST)
    public ResponseEntity addLocation(@RequestBody Map<String,Object> paramMap){
        Double latitude =(Double) paramMap.get("latitude");//纬度 113.929778
        Double longitude =(Double) paramMap.get("longitude");//经度 22.582111
        String addrStr = (String)paramMap.get("addrStr");
        locationService.addLocation(latitude,longitude,addrStr);
        return ResponseEntity.ok(null);
    }


    /**
     * 搜附近
     */
    @RequestMapping(value = "/tanhua/search",method = RequestMethod.GET)
    public ResponseEntity searchNearUser(@RequestParam(defaultValue = "man") String gender, @RequestParam(defaultValue = "2000") String distance){
        List<NearUserVo> list = locationService.searchNearUser(gender,distance);
        return ResponseEntity.ok(list);
    }
}
